package com.ebid.templates.ten;

import java.io.FileWriter;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.List;
import java.util.Map;

public class WinCandidateBulletinPhase {

    private static String winCandidateBulletinPhase = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
        +"<winCandidateBulletinPhase> \n" +
            "    <TENDER_PROJECT_CODE>{0}</TENDER_PROJECT_CODE>\n" +
            "    <BID_SECTION_CODES> \n" +
            "      {1}"+
            "    </BID_SECTION_CODES>\n" +
            "    <TENDER_CODE>{2}</TENDER_CODE>\n" +
            "    <PUBLICITY_NAME>{3}</PUBLICITY_NAME>\n" +
            "    <PUBLICITY_CONTENT>{4}</PUBLICITY_CONTENT>\n" +
            "    <PUBLICITY_TYPE>{5}</PUBLICITY_TYPE>\n" +
            "    <PUBLICITY_START_TIME>{6}</PUBLICITY_START_TIME>\n" +
            "    <PUBLICITY_END_TIME>{7}</PUBLICITY_END_TIME>\n" +
            "    <NOTICE_SEND_TIME>{8}</NOTICE_SEND_TIME>\n" +
            "    <NOTICE_MEDIA>{9}</NOTICE_MEDIA>\n" +
            "    <URL>{10}</URL>\n" +
            "    <OBJECTION_METHOD>{11}</OBJECTION_METHOD>\n" +
            "    <OTHER_CONTENT>{12}</OTHER_CONTENT>\n" +
            "    <BULLETIN_DUTY>{13}</BULLETIN_DUTY>\n" +
            "    <EXAMINER_NAME>{14}</EXAMINER_NAME>\n" +
            "    <SECTIONS_WIN_CANDIDATES> \n" +
            "      {15}"+
            "    </SECTIONS_WIN_CANDIDATES>\n" +
            "    <ATTACHMENT_SET> \n" +
            "      {16}"+
            "    </ATTACHMENT_SET>\n" +
            "    <TRADE_PLAT>{17}</TRADE_PLAT>\n" +
            "    <PUB_SERVICE_PLAT_CODE>{18}</PUB_SERVICE_PLAT_CODE>\n" +
            "    <SUBMIT_TIMESTAMP>{19}</SUBMIT_TIMESTAMP>\n" +
            "  </winCandidateBulletinPhase>";

    private static StringBuilder BID_SECTION_CODES = new StringBuilder();
    private static String BID_SECTION_CODE="<BID_SECTION_CODE>{0}</BID_SECTION_CODE>";

    private static StringBuilder SECTIONS_WIN_CANDIDATES = new StringBuilder();
    private static String SECTIONS_WIN_CANDIDATE ="<SECTIONS_WIN_CANDIDATE> \n"+
            "        <BID_SECTION_CODE>{0}</BID_SECTION_CODE>\n"+
            "        <WIN_CANDIDATES> \n"+
            "           {1}"+
            "        </WIN_CANDIDATES>\n"+
            "      </SECTIONS_WIN_CANDIDATE>";

    private static StringBuilder WIN_CANDIDATES = new StringBuilder();
    private static String WIN_CANDIDATE = "<WIN_CANDIDATE> \n" +
            "            <WIN_CANDIDATE_CODE_TYPE>{0}</WIN_CANDIDATE_CODE_TYPE>\n" +
            "            <WIN_CANDIDATE_CODE>{1}</WIN_CANDIDATE_CODE>\n" +
            "            <WIN_CANDIDATE_NAME>{2}</WIN_CANDIDATE_NAME>\n" +
            "            <WIN_CANDIDATE_ORDER>{3}</WIN_CANDIDATE_ORDER>\n" +
            "            <BID_RESULT> \n" +
            "              <PRICE> \n" +
            "                <BID_PRICE>{4}</BID_PRICE>\n" +
            "                <PRICE_CURRENCY>{5}</PRICE_CURRENCY>\n" +
            "              </PRICE>\n" +
            "              <RATE>{6}</RATE>\n" +
            "              <OTHER_BID_PRICE>{7}</OTHER_BID_PRICE>\n" +
            "            </BID_RESULT>\n" +
            "            <QUALITY>{8}</QUALITY>\n" +
            "            <EVALUATION_STATUS>{9}</EVALUATION_STATUS>\n" +
            "            <WIN_CANDIDATE_QUALIFICATION>{10}</WIN_CANDIDATE_QUALIFICATION>\n" +
            "            <TIME_LIMIT>{11}</TIME_LIMIT>\n" +
            "            <PM_NAME>{12}</PM_NAME>\n" +
            "            <PM_CODE>{13}</PM_CODE>\n" +
            "            <PM_CERTIFICATES>{14}</PM_CERTIFICATES>\n" +
            "          </WIN_CANDIDATE>";

    private static StringBuilder ATTACHMENTS = new StringBuilder();
    private static String ATTACHMENT_SET = "<ATTACHMENT> \n" +
            "        <ATTACHMENT_CODE>{0}</ATTACHMENT_CODE>\n" +
            "        <ATTACHMENT_FILE_NAME>{1}</ATTACHMENT_FILE_NAME>\n" +
            "        <FILE_TYPE>{2}</FILE_TYPE>\n" +
            "        <DATA_TIMESTAMP>{3}</DATA_TIMESTAMP>\n" +
            "        <MD5>{4}</MD5>\n" +
            "      </ATTACHMENT>";


    public static void setBID_SECTION_CODES(String BID_SECTION_CODE,List<Map> lists){
        if (lists == null){
            return;
        }
        for (Map<String,String> map : lists) {
            String args[] = new String[1];
            int i=0;
            for(Map.Entry<String,String> entry : map.entrySet()){
                args[i++] = entry.getValue();
            }
            BID_SECTION_CODE = MessageFormat.format(BID_SECTION_CODE,args);
            BID_SECTION_CODES.append(BID_SECTION_CODE);
        }
    }

    public static void setSECTIONS_WIN_CANDIDATES(String SECTIONS_WIN_CANDIDATE,List<Map> lists){
        if (lists == null){
            return;
        }
        for (Map<String,String> map : lists) {
            String args[] = new String[2];
            int i=0;
            for(Map.Entry<String,String> entry : map.entrySet()){
                args[i++] = entry.getValue();
            }
            SECTIONS_WIN_CANDIDATE = MessageFormat.format(SECTIONS_WIN_CANDIDATE,args);
            SECTIONS_WIN_CANDIDATES.append(SECTIONS_WIN_CANDIDATE);
        }
    }

    public static void setWinCandidate(String WIN_CANDIDATE,List<Map> lists){
        if (lists == null){
            return;
        }
        for (Map<String,String> map : lists) {
            String args[] = new String[15];
            int i=0;
            for(Map.Entry<String,String> entry : map.entrySet()){
                args[i++] = entry.getValue();
            }
            WIN_CANDIDATE = MessageFormat.format(WIN_CANDIDATE,args);
            WIN_CANDIDATES.append(WIN_CANDIDATE);
        }
    }

    public static void setATTACHMENT(String ATTACHMENT,List<Map> lists) {
        if (lists == null){
            return;
        }
        for (Map<String,String> map : lists) {
            String args[] = new String[5];
            int i=0;
            for(Map.Entry<String,String> entry : map.entrySet()){
                args[i++] = entry.getValue();
            }
            ATTACHMENT = MessageFormat.format(ATTACHMENT,args);
            ATTACHMENTS.append(ATTACHMENT);
        }
    }

    public static void setWinCandidateBulletinPhase(String winCandidateBulletinPhase, String s0, String s1, String s2, String s3, String s4, String s5, String s6, String s7, String s8, String s9, String s10,
                                                    String s11, String s12, String s13, String s14, String s15, String s16, String s17, String s18, String s19, String s20) {
        WinCandidateBulletinPhase.winCandidateBulletinPhase = MessageFormat.format(winCandidateBulletinPhase,s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,
                s11,s12,s13,s14,s15,s16,s17,s18,s19,s20);
    }

    public static void setWinCandidateBulletinPhase(){

        setBID_SECTION_CODES(BID_SECTION_CODE,WinCandidateBulletinPhaseUtils.getList(""));

        setWinCandidate(WIN_CANDIDATE,WinCandidateBulletinPhaseUtils.getList(""));
        setSECTIONS_WIN_CANDIDATES(SECTIONS_WIN_CANDIDATE,WinCandidateBulletinPhaseUtils.getList(""));

        setATTACHMENT(ATTACHMENT_SET,WinCandidateBulletinPhaseUtils.getList(""));

        setWinCandidateBulletinPhase(winCandidateBulletinPhase,WinCandidateBulletinPhaseUtils.get(""),
                                                               BID_SECTION_CODES.toString(),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               SECTIONS_WIN_CANDIDATES.toString(),
                                                               ATTACHMENTS.toString(),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get(""),
                                                               WinCandidateBulletinPhaseUtils.get("")

                );
    }

//    public static void main(String[] args) {
//        setWinCandidateBulletinPhase();
//        System.out.println(winCandidateBulletinPhase);
//    }
}
